/**
 * 载信软件(上海)有限公司
 * Copyright (c) 2015-2024 B5M,Inc.All Rights Reserved.
 */
package com.sys.midware.assist.utils.date;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;

import com.sys.midware.assist.utils.string.StringUtil;

/**
 * 日期工具类
 * 
 * @author sjj, </br> sjj@gaoxinyun.com
 * @see com.xuanyan.hmc.midware.assist.utils.DateThreadUtil.abl.nss.spider.utils.DateUtil
 * @version V0.0.1-SNAPSHOT, 2015-2-15 上午10:35:29
 * @description
 *
 */
public class DateUtil {
    
	private final static SimpleDateFormat FM_YYYY = new SimpleDateFormat("yyyy");
	private final static SimpleDateFormat FM_MM = new SimpleDateFormat("MM");
	private final static SimpleDateFormat FM_DD = new SimpleDateFormat("dd");
	private final static SimpleDateFormat FM_HH = new SimpleDateFormat("HH");
	private final static SimpleDateFormat FM_MI = new SimpleDateFormat("mm");
	private final static SimpleDateFormat FM_YYYY_MM_DD_HHMISS = new SimpleDateFormat(
			"yyyy-MM-dd HH:mm:ss");
	private final static SimpleDateFormat FM_YYYY_MM_DD = new SimpleDateFormat(
			"yyyy-MM-dd");
	private final static SimpleDateFormat FM_MMM_YYY = new SimpleDateFormat(
			"MMM yyyy");
	private final static SimpleDateFormat FM_HHMI = new SimpleDateFormat(
			"HH:mm"); // 24 Hours
	private final static SimpleDateFormat FM_YYYYMMDD = new SimpleDateFormat(
			"yyyyMMdd");
	private final static SimpleDateFormat FM_YYYYMM = new SimpleDateFormat(
			"yyyyMM");
	private final static SimpleDateFormat FM_YYYYMMDD_HHMISS = new SimpleDateFormat(
			"yyyyMMddHHmmss");
	private final static SimpleDateFormat FM_YYYYMMDD_HMMSS = new SimpleDateFormat(
			"yyyyMMddHmmss");
	private final static SimpleDateFormat FM_YYYYMMDD_MISS = new SimpleDateFormat(
			"yyyyMMddmmss");
	private final static SimpleDateFormat FM_YYYYMMDDHHMMSS = new SimpleDateFormat(
			"yyyyMMddHHmmss");
	private final static SimpleDateFormat FM_YYYYMMDDHHMMSSSSS = new SimpleDateFormat(
			"yyyyMMddHHmmssSSS");
	private final static SimpleDateFormat FM_YYYY_MM_DD_HH_MI = new SimpleDateFormat(
			"yyyy-MM-dd HH:mm");
	private final static DateFormat FM_NIAN_YUE_RI_SHI_FEN_MIAO= new SimpleDateFormat("yyyy年MM月dd日 hh时mm分ss秒",Locale.CHINA);      
	private final static DateFormat FM_NIAN_YUE_RI_SHI_FEN_MIAO1= new SimpleDateFormat("yyyy年MM月dd日hh时mm分ss秒",Locale.CHINA);    
	private final static DateFormat FM_NIAN_YUE_RI= new SimpleDateFormat("yyyy年MM月dd日",Locale.CHINA);  
	private final static DateFormat FM_NIAN_YUE_RI_SHI_FEN= new SimpleDateFormat("yyyy年MM月dd日 hh时mm分",Locale.CHINA);      
	private final static DateFormat FM_NIAN_YUE_RI_SHI_FEN1= new SimpleDateFormat("yyyy年MM月dd日hh时mm分",Locale.CHINA);     
	/**
	 * 获取当前日期 add by:jackyshang
	 * 
	 * @return
	 */
	public static Date getCurrentDate() {
		return new Date();
	}

	/**
	 * 获取当前日期的23位格式 格式：yyyyMMddHHmmssSSS add by:jackyshang
	 * 
	 * @return
	 */
	public static String getCurDateTimeStr23() {
		Date date = new Date();
		return FM_YYYYMMDDHHMMSSSSS.format(date);
	}
	/**
	 * 获取当前日期的23位格式 格式：yyyyMMddHHmmssSSS add by:jackyshang
	 * 
	 * @return
	 */
	public static String getCurDateStr10() {
		Date date = new Date();
		return FM_YYYY_MM_DD.format(date);
	}
	/**
	 * 获取当前日期的23位格式 格式：yyyyMMddHHmmss add by:jackyshang
	 * 
	 * @return
	 */
	public static String getCurDateTimeStr14() {
		Date date = new Date();
		return FM_YYYYMMDDHHMMSS.format(date);
	}

	/**
	 * 获取当前日期的19位格式 格式：yyyy-MM-dd HH:mm:ss add by:jackyshang
	 * 
	 * @return
	 */
	public static String getCurDateTimeStr19() {
		Date date = new Date();
		return FM_YYYY_MM_DD_HHMISS.format(date);
	}

	/**
	 * 获取当前年份 add by:jackyshang
	 * 
	 * @return
	 */
	public static Integer getCurrentYear() {
		return Integer.valueOf(FM_YYYY.format(getCurrentDate()));
	}

	/**
	 * 获取当前月份 add by:jackyshang
	 * 
	 * @return
	 */
	public static Integer getCurrentMonth() {
		return Integer.valueOf(FM_MM.format(getCurrentDate()));
	}

	/**
	 * 获取当前天 add by:jackyshang
	 * 
	 * @return
	 */
	public static Integer getCurrentDay() {
		return Integer.valueOf(FM_DD.format(getCurrentDate()));
	}
	/**
	 * 获取当前时间毫秒
	 *  add by:jackyshang
	 * 
	 * @return
	 */
	public static Integer getCurrentMilliSecond() {
		Calendar cal = Calendar.getInstance();
		return cal.get(Calendar.MILLISECOND);
	}
	/**
	 * 获取当前时间毫秒
	 *  add by:jackyshang
	 * 
	 * @return
	 */
	public static Long getCurrentDateMilliSecond() {
		return getCurrentDate().getTime();
	}
	/**
	 * 获取前一月日期
	 * 
	 * @return
	 */
	public static Date getPreMonthDate() {
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.MONTH, -1);
		return cal.getTime();
	}

	/**
	 * 获取前一月月份
	 * 
	 * @return
	 */
	public static String getPreMonth() {
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.MONTH, -1);
		return String.valueOf(FM_MMM_YYY.format(cal.getTime()));
	}

	/**
	 * 将19位格式的字符串转为日期类型 格式：yyyy-MM-dd HH:mm:ss
	 * 
	 * @param dateTimeStr19
	 * @return
	 */
	public static Date putFMStr19ToDate(String dateTimeStr19) {
		Date date = null;
		try {
			date = FM_YYYY_MM_DD_HHMISS.parse(dateTimeStr19);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}

	/**
	 * 将19位格式的字符串转为日期类型 格式：yyyy-MM-dd HH:mm:ss
	 * 
	 * @param dateTimeStr19
	 * @return
	 */
	public static String putFMStr19To14(String dateTimeStr19) {
		Date date = null;
		try {
			date = FM_YYYY_MM_DD_HHMISS.parse(dateTimeStr19);
			return FM_YYYYMMDDHHMMSS.format(date);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return "";
	}

	/**
	 * 将时间格式字符串转为日期类型 格式： yyyyMMdd yyyy-MM-dd yyyyMMddmmss yyyyMMddHmmss
	 * yyyyMMddHHmmss
	 * 
	 * @param
	 * @return
	 */
	public static Date putFMStrToDate(String dateTimeStr) {
		if (dateTimeStr == null) {
			return null;
		}
		Date date = null;
		try {
			switch (dateTimeStr.length()) {
			case 8:
				date = FM_YYYYMMDD.parse(dateTimeStr);
				break;
			case 10:
				date = FM_YYYY_MM_DD.parse(dateTimeStr);
				break;
			case 12:
				date = FM_YYYYMMDD_MISS.parse(dateTimeStr);
				break;
			case 13:
				date = FM_YYYYMMDD_HMMSS.parse(dateTimeStr);
				break;
			case 16:
				date = FM_YYYY_MM_DD_HH_MI.parse(dateTimeStr);
				break;
			case 14:
				date = FM_YYYYMMDD_HHMISS.parse(dateTimeStr);
				break;
			case 19:
				date = FM_YYYY_MM_DD_HHMISS.parse(dateTimeStr);
				break;
			case 17:
				date = FM_YYYY_MM_DD_HHMISS.parse(dateTimeStr);
				break;
			case 18:
				date = FM_YYYY_MM_DD_HHMISS.parse(dateTimeStr);
				break;
			default:
				break;
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}
	/**
	 * 将时间格式字符串转为日期类型 
	 * 格式： 年月日时分秒
	 * 
	 * @param
	 * @return
	 */
	public static Date putFMChToDate(String dateTimeStr) {
		if (dateTimeStr == null) {
			return null;
		}
		Date date=null;
		try {
			switch (dateTimeStr.length()) {
			case 11:
				date = FM_NIAN_YUE_RI.parse(dateTimeStr);
				break;
			case 17:
				date = FM_NIAN_YUE_RI_SHI_FEN1.parse(dateTimeStr);
				break;
			case 18:
				date = FM_NIAN_YUE_RI_SHI_FEN.parse(dateTimeStr);
				break;
			case 20:
				date = FM_NIAN_YUE_RI_SHI_FEN_MIAO1.parse(dateTimeStr);
				break;
			case 21:
				date = FM_NIAN_YUE_RI_SHI_FEN_MIAO.parse(dateTimeStr);
				break;
			default:
				break;
			}
			
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}
	/**
	 * 格式化日期为时分 格式：HH:mm create by:jackyshang
	 * 
	 * @param date
	 * @return
	 */
	public static String putDateToTimeHhMm(Date date) {
		return FM_HHMI.format(date);
	}

	/**
	 * 格式化日期为时分 格式：yyyy-MM-dd 
	 * create by:jackyshang
	 * @param date
	 * @return
	 */
	public static String putDateToTimeStr10(Date date) {
		if(date==null){
			return null;
		}
		return FM_YYYY_MM_DD.format(date);
	}
	/**
	 * 格式化日期为时分 格式：yyyy-MM-dd HH:MM:SS
	 * create by:jackyshang
	 * 
	 * @param date
	 * @return
	 */
	public static String putDateToTimeStr19(Date date) {
		if(date ==null){
			return null;
		}
		return FM_YYYY_MM_DD_HHMISS.format(date);
	}
	
//	public static String putDateToTimeStr16(Date date) {
//        if(date ==null){
//            return null;
//        }
//        return FM_YYYYMMDDHHMMSS.format(date);
//    }
	
	   public static String putDateToTimeStr14(Date date) {
	        if(date ==null){
	            return null;
	        }
	        return FM_YYYYMMDDHHMMSS.format(date);
	    }
	/**
	 * 格式化日期为时分 格式：yyyyMM
	 *  create by:jackyshang
	 * @param date
	 * @return
	 */
	public static String putDateToYYYYMMStr(Date date) {
		String dateStr = null;
		if (date != null)
			dateStr = FM_YYYYMM.format(date);
		return dateStr;
	}

	/**
	 * 格式化日期为时分 格式：yyyyMM create by:jackyshang
	 * 
	 * @param date
	 * @return
	 */
	public static String putDateToDDStr(Date date) {

		String dateStr = null;
		if (date != null)
			dateStr = FM_DD.format(date);
		return dateStr;
	}

	/**
	 * 格式化日期为时分 格式：HH create by:jackyshang
	 * 
	 * @param date
	 * @return
	 */
	public static String putDateToHHStr(Date date) {

		String dateStr = null;
		if (date != null)
			dateStr = FM_HH.format(date);
		return dateStr;
	}

	/**
	 * 格式化日期为时分 格式：mi create by:jackyshang
	 * 
	 * @param date
	 * @return
	 */
	public static String putDateToMIStr(Date date) {

		String dateStr = null;
		if (date != null)
			dateStr = FM_MI.format(date);
		return dateStr;
	}

	/**
	 * 格式化日期为时分 格式：yyyyMMdd create by:jackyshang
	 * 
	 * @param date
	 * @return
	 */
	public static String putDateToYYYYMMDDStr(Date date) {
		String dateStr = null;
		if (date != null)
			dateStr = FM_YYYYMMDD.format(date);
		return dateStr;
	}

	/**
	 * 将当期日期转为当月第一天 例如：当前日期为：2014-08-22 15:23:40 转换后为 2014-08-01 15:23:40
	 * 
	 * @param dateTime
	 * @return
	 */
	public static Date convertDateToFirstDay(Date dateTime) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(dateTime);
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		return calendar.getTime();
	}

	/**
	 * 将当期日期转为最后一天 例如：当前日期为：2014-08-22 15:23:40 转换后为 2014-08-31 15:23:40
	 * 
	 * @param dateTime
	 * @return
	 */
	public static Date convertDateToLastDay(Date dateTime) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(dateTime);
		calendar.set(Calendar.DAY_OF_MONTH,
				calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
		return calendar.getTime();
	}

	/**
	 * 用于获得日期的年月的字符串 例如：2014-8-22 15:23:40 返回的值为2014-08
	 * 
	 * @param dateTime
	 * @param format
	 * @return
	 */
	public static String convertFormatDate(Date dateTime, String... format) {
		String _format = "yyyy/MM/dd";
		if (format != null && format.length > 0) {
			String s = StringUtil.trim(format[0]);
			if (s != null && !"".equals(s)) {
				_format = s;
			}
		}

		SimpleDateFormat DATE_MONTH_FORMAT = new SimpleDateFormat(_format);
		return DATE_MONTH_FORMAT.format(dateTime);
	}

	/**
	 * 用于将时间取整到小时 或者到分 例如：2014-8-22 15:23:40 取整后为 2014-8-22 15:00:00
	 * 
	 * @param dateTime
	 * @param format
	 * @return
	 */
	public static Date convertFormatDateStr(String dateTime, String... format) {
		String _format = "yyyy/MM/dd";
		if (format != null && format.length > 0) {
			String s = StringUtil.trim(format[0]);
			if (s != null && !"".equals(s)) {
				_format = s;
			}
		}

		SimpleDateFormat DATE_MONTH_FORMAT = new SimpleDateFormat(_format);
		try {
			return DATE_MONTH_FORMAT.parse(dateTime);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * 比较开始时间和结束时间 1.beginDateTime < endDateTime，返回1 2.beginDateTime >
	 * endDateTime，返回-1 3.beginDateTime = endDateTime，返回0
	 * 
	 * @param beginDateTime
	 * @param endDateTime
	 * @return
	 */
	public static int compareDate(Date beginDateTime, Date endDateTime) {
		long bt = beginDateTime.getTime();
		long et = endDateTime.getTime();
		long mt = et - bt;
		if (mt == 0) {
			return 0;
		}
		return mt > 0 ? 1 : -1;
	}

	/**
	 * 获得日期的年份
	 * 
	 * @param dateTime
	 * @return
	 */
	public static int getYear(Date dateTime) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(dateTime);
		return calendar.get(Calendar.YEAR);
	}

	/**
	 * 获得日期的月份
	 * 
	 * @param dateTime
	 * @return
	 */
	public static int getMonth(Date dateTime) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(dateTime);
		return calendar.get(Calendar.MONTH);
	}

	/**
	 * 获得日期的天
	 *
	 * @param dateTime
	 * @return
	 */
	public static int getDay(Date dateTime) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(dateTime);
		return calendar.get(Calendar.DAY_OF_MONTH);
	}

	/**
	 * 获得日期的小时
	 * 
	 * @param dateTime
	 * @return
	 */
	public static int getHour(Date dateTime) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(dateTime);
		return calendar.get(Calendar.HOUR_OF_DAY);
	}

	/**
	 * 是否为当前年月
	 * 
	 * @param beginDateTime
	 * @param endDateTime
	 * @return
	 */
	public static boolean isCurrentYearMonth(Date beginDateTime,
			Date endDateTime) {
		int b_year = getMonth(beginDateTime);
		int b_month = getYear(beginDateTime);
		int e_year = getMonth(endDateTime);
		int e_month = getYear(endDateTime);

		if (b_year == e_year && b_month == e_month) {
			return true;
		}
		return false;
	}

	/**
	 * 是否为当天
	 * 
	 * @param beginDateTime
	 * @param endDateTime
	 * @return
	 */
	public static boolean isCurrentDay(Date beginDateTime, Date endDateTime) {
		int b_year = getMonth(beginDateTime);
		int b_month = getYear(beginDateTime);
		int b_day = getDay(beginDateTime);
		int e_year = getMonth(endDateTime);
		int e_month = getYear(endDateTime);
		int e_day = getDay(endDateTime);

		if (b_year == e_year && b_month == e_month && b_day == e_day) {
			return true;
		}
		return false;
	}

	/**
	 * 是否为当天
	 * 
	 * @param beginDateTime
	 * @param endDateTime
	 * @return
	 */
	public static boolean isInner24Hour(Date beginDateTime, Date endDateTime) {
		long b_millis = beginDateTime.getTime();
		long e_millis = endDateTime.getTime();
		long m_millis = e_millis - b_millis;
		long d_millis = 1000 * 60 * 60 * 24;

		if (m_millis <= d_millis) {
			return true;
		}
		return false;
	}

	/**
	 * 获得昨天23:59:59的时间
	 * 
	 * @param date
	 * @return
	 */
	public static Date getYesterday(Date date) {
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		c.add(Calendar.DAY_OF_MONTH, -1);
		c.set(Calendar.HOUR_OF_DAY, c.getMaximum(Calendar.HOUR_OF_DAY));
		c.set(Calendar.MINUTE, c.getMaximum(Calendar.MINUTE));
		c.set(Calendar.SECOND, c.getMaximum(Calendar.SECOND));
		return c.getTime();
	}

	/**
	 * 取这个时间段内每个月的最后一天
	 * 
	 * @param beginDateTime
	 * @param endDateTime
	 * @return
	 */
	public static List<Date> getEveryLastDayList(Date beginDateTime,
			Date endDateTime) {
		int b_year = getYear(beginDateTime);
		int e_year = getYear(endDateTime);
		int b_month = getMonth(beginDateTime);
		int e_month = getMonth(endDateTime);

		int m = (e_year - b_year) * 12 + (e_month - b_month);
		List<Date> list = new ArrayList<Date>();
		for (int i = 0; i <= m; i++) {
			Calendar c = Calendar.getInstance();
			c.setTime(beginDateTime);
			c.add(Calendar.MONTH, i);
			c.set(Calendar.DAY_OF_MONTH,
					c.getActualMaximum(Calendar.DAY_OF_MONTH));
			list.add(c.getTime());
		}
		return list;
	}

	/**
	 * 获取时间段内的所有天数
	 *
	 * @param beginDateTime
	 * @param endDateTime
	 * @return
	 */
	public static List<Date> getEveryDayList(Date beginDateTime,
			Date endDateTime) {
		long b_millis = beginDateTime.getTime();
		long e_millis = endDateTime.getTime();
		long m_millis = e_millis - b_millis;
		long d_millis = 1000 * 60 * 60 * 24;
		long m_days = m_millis / d_millis;

		if (m_millis <= 0) {
			return null;
		}

		List<Date> list = new ArrayList<Date>();
		list.add(beginDateTime);

		for (int i = 0; i < m_days; i++) {
			b_millis = b_millis + d_millis;
			Calendar c = Calendar.getInstance();
			c.setTimeInMillis(b_millis);
			list.add(c.getTime());
		}

		m_millis = e_millis - b_millis;
		if (m_millis > 0) {
			Calendar c = Calendar.getInstance();
			c.setTimeInMillis(e_millis);
			list.add(c.getTime());
		}
		return list;
	}

	/**
	 * 
	 * @param beginDateTime
	 * @param endDateTime
	 * @return
	 */
	public static List<Date> getEveryMonthList(Date beginDateTime,
			Date endDateTime) {
		long b_millis = beginDateTime.getTime();
		long e_millis = endDateTime.getTime();
		long m_millis = e_millis - b_millis;
		if (m_millis <= 0) {
			return null;
		}
		int b_year = getYear(beginDateTime);
		int e_year = getYear(endDateTime);
		int b_month = getMonth(beginDateTime);
		int e_month = getMonth(endDateTime);
		int m = (e_year - b_year) * 12 + (e_month - b_month);

		List<Date> list = new ArrayList<Date>();
		list.add(beginDateTime);

		for (int i = 0; i <= m; i++) {
			Calendar c = Calendar.getInstance();
			c.setTime(beginDateTime);
			c.add(Calendar.MONTH, 1);

			beginDateTime = c.getTime();
			b_millis = beginDateTime.getTime();

			if (b_millis > e_millis) {
				list.add(endDateTime);
				break;
			} else {
				list.add(beginDateTime);
			}
		}
		return list;
	}

	/**
	 * 获取时间段内所有的年月
	 * 
	 * @param beginDateTime
	 * @param endDateTime
	 * @param format
	 * @return
	 */
	public static HashSet<String> getEveryYearMonth(Date beginDateTime,
			Date endDateTime, String... format) {
		int b_year = getYear(beginDateTime);
		int e_year = getYear(endDateTime);
		int b_month = getMonth(beginDateTime);
		int e_month = getMonth(endDateTime);

		int m = (e_year - b_year) * 12 + (e_month - b_month);
		HashSet<String> reSet = new HashSet<String>();
		for (int i = 0; i <= m; i++) {
			Calendar c = Calendar.getInstance();
			c.setTime(beginDateTime);
			c.add(Calendar.MONTH, i);
			reSet.add(convertFormatDate(c.getTime(), format));
		}
		return reSet;
	}

	public static List<String> getEveryYearMonthList(Date beginDateTime,
			Date endDateTime, String... format) {
		int b_year = getYear(beginDateTime);
		int e_year = getYear(endDateTime);
		int b_month = getMonth(beginDateTime);
		int e_month = getMonth(endDateTime);

		int m = (e_year - b_year) * 12 + (e_month - b_month);
		List<String> list = new ArrayList<String>();
		for (int i = 0; i <= m; i++) {
			Calendar c = Calendar.getInstance();
			c.setTime(beginDateTime);
			c.add(Calendar.MONTH, i);
			list.add(convertFormatDate(c.getTime(), format));
		}
		return list;
	}

	/***
	 * 月份加减
	 * 
	 * @param datetime
	 *            日期(2014-11)
	 * @return 2014-10
	 */
	public static Date addMonths(Date dateVal, int num) {
		Date date = null;
		try {
			date = FM_YYYY_MM_DD.parse(putDateToTimeStr10(dateVal));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		Calendar cl = Calendar.getInstance();
		cl.setTime(date);
		cl.add(Calendar.MONTH, num);
		date = cl.getTime();
		return date;
	}

	/***
	 * 日期加减
	 * 
	 * @param datetime
	 *            日期(2014-11)
	 * @return 2014-10
	 */
	public static Date addDays(Date dateVal, int num) {
		Calendar cl = Calendar.getInstance();
		cl.setTime(dateVal);
		cl.add(Calendar.DAY_OF_YEAR, num);
		dateVal = cl.getTime();
		return dateVal;
	}

	/**
	 * time=yyyy-m-d
	 * 
	 * @param dateTimeStr8
	 * @return
	 */
	public static Date putFMStr8ToDate(String dateTimeStr8) {

		String[] dateStr = dateTimeStr8.split("-");
		for (int i = 0; i < dateStr.length; i++) {
			if (i == 0) {
				dateTimeStr8 = dateStr[i];
				continue;
			}
			if (Integer.parseInt(dateStr[i]) < 10) {
				dateTimeStr8 += "-0" + dateStr[i];
			} else {
				dateTimeStr8 += "-" + dateStr[i];
			}
		}
		Date date = null;
		try {
			date = FM_YYYY_MM_DD.parse(dateTimeStr8);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}
	
	/**
	 * 格式化时间为标准的yyyy_MM_dd HH:MM:SS
	 * 
	 * @param dateTimeStr8
	 * @return
	 */
	public static String formartDateStrToStand  (String dateTimeStr) {
		if(dateTimeStr==null){
			return dateTimeStr;
		}
		String[] dateTimeArry=	dateTimeStr.split(" ");
		String[] dateArry = dateTimeArry[0].split("-");
		String retDate="";
		if(dateArry!=null && dateArry.length>0){
			for(String date : dateArry){
				if(date.length() ==1){
					retDate += "0" +date +"-";
				}else{
					retDate += date +"-";
				}
			}
			if(retDate.endsWith("-")){
				retDate=retDate.substring(0,retDate.length()-1);
			}
		}
		//如果有时间格式，则拼装时间 
		if(dateTimeArry.length >=2){
			String[] timeArry = dateTimeArry[1].split(":");
			String retTime="";
			if(timeArry !=null && timeArry.length >0){
				for(String time : timeArry){
					if(time.length() ==1){
						retTime += "0" +time +":";
					}else{
						retTime +=time +":";
					}
				}
			}
			if(retTime.endsWith(":")){
				retTime=retTime.substring(0,retTime.length()-1);
			}
			retDate+=" "+ retTime;
		}
		return retDate;
	}

	/**
	 * 
	 *
	 * @description
	 * @param timestamp
	 *            类似于1426291200
	 * @return
	 */
	public static String timestampToDate(Long timestamp) {
		return FM_YYYY_MM_DD_HHMISS
				.format(new java.util.Date(timestamp ));
	}
	

	
    /**  
     * 计算两个日期之间相差的天数  
     * @param smdate 较小的时间 
     * @param bdate  较大的时间 
     * @return 相差天数 
     * @throws ParseException  
     */    
	public static int daysBetween(Date mindate, Date maxdate) {
		try {
			mindate = FM_YYYY_MM_DD.parse(FM_YYYY_MM_DD.format(mindate));
			maxdate = FM_YYYY_MM_DD.parse(FM_YYYY_MM_DD.format(maxdate));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		Calendar cal = Calendar.getInstance();
		cal.setTime(mindate);
		long time1 = cal.getTimeInMillis();
		cal.setTime(maxdate);
		long time2 = cal.getTimeInMillis();
		long between_days = (time2 - time1) / (1000 * 3600 * 24);

		return Integer.parseInt(String.valueOf(between_days));
	}
	/**
	 * 获取当前月第一天的毫秒数
	 * @param  
	 * @return  Long
	 */
    public static Long getFirstDayCurrentMonth(){
        GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
        gc.set(Calendar.DAY_OF_MONTH, 1);
        return  gc.getTime().getTime();
    }
	
}
